<template>
  <div>
    <!-- 面包屑 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片区域 -->
    <el-card>
      <!-- 筛选区域 -->
      <el-row style="margin-bottom: 15px">
        <el-col :span="8">
          <el-input placeholder="请输入内容" v-model="queryInfo.query">
            <el-button
              slot="append"
              icon="el-icon-search"
              @click="getOrderList()"
            ></el-button>
          </el-input>
        </el-col>
      </el-row>
      <!-- 数据列表 -->
      <el-table :data="orderDataList" style="width: 100%" border>
        <el-table-column type="index" label="#"></el-table-column>
        <el-table-column
          prop="order_number"
          label="订单编号"
          width="240"
        ></el-table-column>
        <el-table-column prop="order_price" label="订单价格"></el-table-column>
        <el-table-column label="订单状态">
          <template slot-scope="scope">
            <div>
              <el-tag v-if="scope.row.pay_status === '0'" type="danger"
                >未支付</el-tag
              >
              <el-tag v-else type="success">已支付</el-tag>
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="is_send" label="是否发货"></el-table-column>
        <el-table-column prop="create_time" label="下单时间">
          <template slot-scope="scope">
            <div>{{ scope.row.create_time | dateFormat }}</div>
          </template>
        </el-table-column>
        <el-table-column prop="create_time" label="下单时间" width="150">
          <template>
            <div>
              <el-button
                type="primary"
                icon="el-icon-edit"
                size="mini"
                @click="handleCheckAdrees"
              ></el-button>
              <el-button
                type="success"
                icon="el-icon-location-outline"
                size="mini"
                @click="showFiexDialog"
              ></el-button>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <!-- 数据分页 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="orderDataList.pagenum"
        :page-sizes="[5, 10, 15]"
        :page-size="orderDataList.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </el-card>
    <!-- 修改地址弹窗 -->
    <el-dialog
      title="修改地址"
      :visible.sync="checkAdreesVisible"
      width="50%"
      @close="addressFormClose"
    >
      <span>
        <el-form
          :model="checkAdreesForm"
          ref="checkAdreesFormRef"
          :rules="checkAdreesFormRules"
          label-width="100px"
        >
          <el-form-item label="省市区/县" prop="addres1">
            <el-cascader
              :options="cityData"
              v-model="checkAdreesForm.addres1"
            ></el-cascader>
          </el-form-item>
          <el-form-item prop="addres2" label="具体地址">
            <el-input v-model="checkAdreesForm.addres2"></el-input>
          </el-form-item>
        </el-form>
      </span>
      <span slot="footer" class="dialog-footer">
        <el-button @click="checkAdreesVisible = false">取 消</el-button>
        <el-button type="primary" @click="checkAdreesVisible = false"
          >确 定</el-button
        >
      </span>
    </el-dialog>
    <!-- 快递查询 -->
    <el-dialog title="快递查询" :visible.sync="fiexDialogVisiable" width="50%">
      <el-timeline>
        <el-timeline-item
          v-for="(activity, index) in fiexList"
          :key="index"
          :timestamp="activity.timestamp"
        >
          {{ activity.content }} </el-timeline-item
        ><!--  -->
      </el-timeline>
    </el-dialog>
  </div>
</template>
<script>
import cityData from "./citydata.js";
export default {
  data() {
    return {
      queryInfo: {
        query: "",
        pagenum: 1,
        pagesize: 10,
      },
      total: 0,
      orderDataList: [],
      checkAdreesVisible: false,
      checkAdreesForm: {
        addres1: [],
        addres2: "",
      },
      checkAdreesFormRules: {
        addres1: [
          { required: true, message: "请选择省市区县", trigger: "blur" },
        ],
        addres2: [
          { required: true, message: "具体地址不能为空", trigger: "blur" },
        ],
      },
      cityData: cityData,
      cityDataArriy: [],
      fiexDialogVisiable: false,
      /* 物流信息查询 */
      fiexList: [
        {
          content: "活动按期开始",
          timestamp: "2018-04-15",
        },
        {
          content: "通过审核",
          timestamp: "2018-04-13",
        },
        {
          content: "创建成功",
          timestamp: "2018-04-11",
        },
      ],
    };
  },
  created() {
    this.getOrderList();
  },
  methods: {
    async getOrderList() {
      const { data: res } = await this.$http.get("/orders", {
        params: this.queryInfo,
      });

      if (res.meta.status !== 200) {
        return console.error("查询订单数据失败");
      }
      console.log(res.data);
      this.orderDataList = res.data.goods;
      this.total = res.data.total;
    },
    handleSizeChange(newSize) {
      this.queryInfo.pagesize = newSize;
      this.getOrderList();
    },
    handleCurrentChange(newCurrent) {
      this.queryInfo.pagenum = newCurrent;
      this.getOrderList();
    },
    handleCheckAdrees() {
      this.checkAdreesVisible = true;
    },
    handleChange() {
      this.checkAdreesForm.addres1.forEach((item) => {
        console.log(item);
      });
    },
    addressFormClose() {
      this.$refs.checkAdreesFormRef.resetFields();
    },
    async showFiexDialog() {
      this.fiexDialogVisiable = true;
      //const { data: res } = await this.$http.get("/kuaidi/804909574412544580");

      /* if (res.meta.status !== 200) {
        return this.$message.error("查询物流信息失败！");
      }
      this.fiexList = res.data;
      this.fiexDialogVisiable = true;
      console.log(this.fiexList); */
    },
  },
};
</script>
<style lang="less" scoped></style>
